import 'package:flutter/material.dart';

class SwitchAndCheckBoxTest  extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _SwitchAndCheckBoxTestState();
  }
  
}

class _SwitchAndCheckBoxTestState extends State<SwitchAndCheckBoxTest>{
 bool _switchSelected=true; //维护单选开关状态
  bool _checkboxSelected=true;//维护复选框状态

  @override
  Widget build(Object context) {
    return Column(
      children: [
        Switch(
          value: _switchSelected, 
        onChanged:(value){
          setState(() {
            _switchSelected = value;
          });

        }),
        Checkbox(
          value: _checkboxSelected,
          activeColor: Colors.red, //选中时的颜色
           onChanged: (value){
            if(value != null){
              setState(() {
                  _checkboxSelected=value;
              });
            }
          
          })
      ],
    );
      
  }

}